<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>挂号界面</title>
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="static/easyui/themes/icon.css">
<link rel="stylesheet" href="static/easyui/themes/ui-cupertino/easyui.css">
</head>
<body>
<style type="text/css">
 .text-css{
	border: 0px;
    border-bottom: 1px solid #aaa;
    background: #dee;
    text-align: center;
    width: 80px;
    height: 24px;
    outline: none;
    font-style: italic;
}
</style>
<script type="text/javascript">
//时间转换
function comformatDate(date){
	var day = new Date(date); 
	var Year = 0; 
	var Month = 0; 
	var Day = 0; 
	var CurrentDate = ""; 
	//初始化时间 
	Year= day.getFullYear();//
	Month= day.getMonth()+1; 
	Day = day.getDate(); 
	Hour = day.getHours(); 
	 Minute = day.getMinutes(); 
	 Second = day.getSeconds(); 
	CurrentDate += Year + "-"; 
	if (Month >= 10 ) { 
		CurrentDate += Month + "-"; 
	}else { 
		CurrentDate += "0" + Month + "-"; 
	} 
	if (Day >= 10 ) { 
		CurrentDate += Day ; 
	}else { 
		CurrentDate += "0" + Day ; 
	} 
	if(Hour>=10){
		CurrentDate +=" "+Hour;
	}else{
		CurrentDate +=" "+"0"+Hour;
	}
	if(Minute>=10){
		CurrentDate +=":"+Minute;
	}else{
		CurrentDate +=":"+"0"+Minute;
	}
	if(Second>=10){
		CurrentDate +=":"+Second;
	}else{
		CurrentDate +=":"+"0"+Second;
	}
	return CurrentDate; 
};
		$(function(){
			//挂号记录访问数据源、初始化表格
			$('#guahao_tb').datagrid({
			    url:'px-jilu',
				pagination:true,
			    pageNumber:1,
			    pageSize:6,
			    pageList:[6,6],
			    columns:[[
					{field:'outpatient_id',title:'门诊号',width:100,align:'center'},
					{field:'mecard_number',title:'诊疗卡号',width:151.5,align:'center'},
					{field:'patient_name',title:'病人姓名',width:101.5,align:'center'},
					{field:'ghlx_name',title:'挂号类型',width:80,align:'center'},
					{field:'registration_date',title:'挂号日期',width:171.5,align:'center',formatter:comformatDate},
					{field:'departments_name',title:'所挂科室',width:80,align:'center'},
					{field:'registration_money',title:'挂号金额',width:80,align:'center'},
					{field:'kzfy',title:'看诊金额',width:100,align:'center'},
					{field:'ghblr',title:'办理人',width:101.5,align:'center'}
			    ]]
			});
		});
		//判断输入的实付金额
		$(function(){
			$("#ghss").blur(function(){
				//取到实收费用
				var ghss=$('#ghss').val();
				var ghzje=$('#ghzje').text();
				if(ghss==''){
					$.messager.alert("温馨提示：","输入不能为空");
				}else if(!(/^([1-9]\d*|[0]{1,1})$/).test(ghss)){
					/* $.messager.alert("温馨提示：","请输入数字"); */
					$('#ghss').val(0);
				}else if(parseInt(ghss)<parseInt(ghzje)){
					$.messager.alert("温馨提示：","所交钱不够");
				}else{
					//取到实收费用
					var ghss=$('#ghss').val();
					var ghzje=$('#ghzje').text();
					/* alert("实付"+ghss+"总金额"+ghzje); */
					var ghzl=parseInt(ghss)-parseInt(ghzje);
					/* alert("实付"+ghss+"总金额"+ghzje+"找零"+ghzl); */
					$("#ghzl").text(ghzl);
					return;
				}
				
			});
		});
		
		
		//=================挂号新增
		$(function(){
			//确认挂号事件
			$("#qd").click(function(){
				//取到实收费用
				var ghss=$('#ghss').val();
				if(ghss==''){
					$.messager.alert("温馨提示：","支付金额不能为空");
				}else{
				var ghzje=$('#ghzje').text();
				var ghzl=$('#ghzl').text();
				//医疗卡号
				var yid=$('#ghylkh').val();
					$("#mecardnumber").val(yid);//把输入的医疗卡卡号存进隐藏域打印票据时调用
				//科室
				var keshi=$("#department_").textbox("getValue");
				//挂号类型
				var ghlx=$("#department_type").textbox("getValue");
				//医生
				var user_id=$('#yishen').textbox("getValue");
				//看诊费用
				var kzfy=$('#kzfy').val();	
				//挂号金额
				var ghje=$("#ghje").val();
				if(yid==''){
					$.messager.alert("温馨提示：","您还未添加病人信息");
					$("#yid").textbox("setValue",null); 
					$("#brxm").textbox("setValue",null);
					$("#brnl").textbox("setValue",null); 
					$("#brxb").textbox("setValue",null); 
					$("#crd").textbox("setValue",null); 
					$("#department_").textbox("setValue",null);
					$("#yishen").textbox("setValue",null);
					$("#tel").textbox("setValue",null);
					$("#department_type").textbox("setValue",null);
					$("#ghje").textbox("setValue",null);
					$("#brdizhi").textbox("setValue",null);
					$("#ghss").val(0);
					$("#ghzl").text(0);
					$("#ghzje").text(0);
				}else if(ghzje==''){
					$.messager.alert("温馨提示：","总金额不能为空");
				}else if(ghzl==''){
					$.messager.alert("温馨提示：","挂号找零不能为空");
				}else if(keshi==''){
					$.messager.alert("温馨提示：","挂号科室不能为空");
				}else if(ghlx==''){
					$.messager.alert("温馨提示：","挂号类型不能为空");
				}else if(user_id==''){
					$.messager.alert("温馨提示：","用户编号不能为空");
				}else if(kzfy==''){
					$.messager.alert("温馨提示：","看诊费用不能为空");
				}else if(ghje==''){
					$.messager.alert("温馨提示：","挂号金额不能为空");
				}else if(ghss==0){
					$.messager.alert("温馨提示：","对不起你未支付挂号金额");
				}else {
					$.ajax({
						url:'xzghjl',
						type:'post',
						data:{
							"mecardNumber":yid,
							"userId":user_id,
							"kzfy":kzfy,
							"departments_id":keshi,
							"ghlx_id":ghlx,
							"ghlx_money":ghje,
							"ghzj":ghzje,
							"ghss":ghss,
							"ghzl":ghzl
								 
						},
						success:function(d){
							if(parseInt(d)==1){
								 $("#guahao_tb").datagrid("reload");
								 $("#ghwc").window("open");
					 		}else{
					 			$.messager.alert("温馨提示：","挂号新增失败");
					 		}
						}
					});
				}
				
				}	
		});
		//取消挂号事件
		$("#qx").click(function(){
			$("#yid").textbox("setValue",null); 
			$("#brxm").textbox("setValue",null);
			$("#brnl").textbox("setValue",null); 
			$("#brxb").textbox("setValue",null); 
			$("#crd").textbox("setValue",null); 
			$("#department_").textbox("setValue",null);
			$("#yishen").textbox("setValue",null);
			$("#tel").textbox("setValue",null);
			$("#department_type").textbox("setValue",null);
			$("#ghje").textbox("setValue",null);
			$("#brdizhi").textbox("setValue",null);
			$("#ghss").val(0);
			$("#ghzl").text(0);
			$("#ghzje").text(0);
			$("#ghylkh").textbox("setValue",null);
		});
		
		});
		//初始化所有科室下拉列表
	 $(function(){
			//初始化科室下拉列表
			$('#department_').combobox({
			    url:'findMzks',//数据源
			    valueField:'departments_id',//实际值
			    textField:'departments_name',//显示值
			    onSelect:function(row){
			    	//初始化医生下拉列表
			    	$("#yishen").combobox({
			    		url:'cxsbys?ksid='+row["departments_id"],
			    		valueField:"user_id",
			    		textField:"user_name",
			    		
			    	});
			    }
			});
		});
	//初始化所有挂号类型下拉列表
		$(function(){
			//初始化科室下拉列表
			$('#department_type').combobox({
			    url:'ghlx', //数据源 
			    valueField:'ghlx_id',//实际值
			    textField:'ghlx_name',//展示值
			    
			   	onSelect:function(row){
			   		//选择对应的挂号类型给挂号金额input赋值
			   		$("#ghje").textbox("setValue",row['ghlx_money']);
			   		var kzfy=$('#kzfy').val();
			   		var ff=parseInt(kzfy)+parseInt(row.ghlx_money);
			   		$("#ghzje").text(ff);
			   	}
			});
		}); 
		//挂号医疗卡搜索事件
		$('#ghylkh').searchbox({
		searcher:function(value,name){
			if(value==''){
				$.messager.alert("温馨提示：","对不起不能输入为空！");
			}else{
			$.ajax({
				url:'yikcx',
				type:'post',
				data:{
					"mzcard_id":value
				},
				success:function(d){
					if(d==''){
						$.messager.alert("温馨提示：","对不起你的医疗卡已挂失！");
					}else{
						$("#brxm").textbox("setValue",d[0]["patient_name"]); 
						$("#brnl").textbox("setValue",d[0]["patient_age"]); 
						$("#brxb").textbox("setValue",d[0]["patient_sex"]);
						$("#tel").textbox("setValue",d[0]["mzcard_phone"]);
						$("#crd").textbox("setValue",d[0]["card_cid"]);
						$("#brdizhi").textbox("setValue",d[0]["home_address"]);
					}
					
					
				}
			})
			}
		  } 
	});
		//====================挂号打印票据
		$(function(){
			$("#ghdy").click(function(){
				var mecardnumber=$('#mecardnumber').val();//调用存在隐藏域的医疗卡编号
				 $.ajax({
					url:'idcgh?mecard_number='+mecardnumber,
					type:'post',
					success:function(d){
						$("#patient_hid").val(d[0]["departments_name"]); //科室
						$("#bedText").val(d[0]["user_name"]); //医生
						$("#ghlx_name").val(d[0]["ghlx_name"]); //类型
						$("#ghpjkzf").val(d[0]["kzfy"]); //看诊费
						$("#ghpjghf").val(d[0]["registration_money"]); //挂号费
						$("#ghzfy").text(d[0]["ghzj"]); //挂号总费用
						$("#ghpjss").text(d[0]["ghss"]); //挂号实收
						$("#ghbrxm").text(d[0]["patient_name"]); //病人姓名
						$("#ghpjzl").text(d[0]["ghzl"]); //挂号找零
						$("#ghskr").text(d[0]["ghblr"]);//挂号收费人
						
							
						var dateee = new Date(d[0]["registration_date"]).toJSON();
						var date= new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, ''); 
						//体检项目收费时间
						$("#ghsfsj").text(date);
						//体检项目收费单号
						var date = new Date(+new Date()+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'');
						var  hhhh=date.toString().replace("-", "");
						var  hhhhh=hhhh.toString().replace(":", "");
						var  aa=hhhhh.toString().replace(":", "");
						var  aaa=aa.toString().replace("-", "");
						var  aaaa=aaa.toString().replace(" ", "");
						$("#ghsfbh").text(aaaa);
					}
				});
				
				$("#guahaoshoufei").window("open");
				$("#yid").textbox("setValue",null); 
				$("#brxm").textbox("setValue",null);
				$("#brnl").textbox("setValue",null); 
				$("#brxb").textbox("setValue",null); 
				$("#crd").textbox("setValue",null); 
				$("#department_").textbox("setValue",null);
				$("#yishen").textbox("setValue",null);
				$("#tel").textbox("setValue",null);
				$("#department_type").textbox("setValue",null);
				$("#ghje").textbox("setValue",null);
				$("#brdizhi").textbox("setValue",null);
				$("#ghss").val(0);
				$("#ghzl").text(0);
				$("#ghzje").text(0);
				$("#ghylkh").textbox("setValue",null);
			});
			$("#ghdywc").click(function(){
				$("#guahaoshoufei").window("close");
				$("#ghwc").window("close");
			});
			/* $('#busfz').searchbox({
				searcher:function(value,name){
				    $('#bu_patient').datagrid({
				    	url:'sfzsy?card_cid='+value,
				    	 columns:[[
						    	{field:'mzcard_id',hidden:'true',title:'编号',width:160,align:'center'},
								{field:'mecard_number',title:'医疗卡编号',width:160,align:'center'},
								{field:'patient_name',title:'病人姓名',width:86,align:'center'},
								{field:'patient_age',title:'病人年龄',width:86,align:'center'},
								{field:'patient_sex',title:'病人性别',width:86,align:'center'},
								{field:'card_cid',title:'病人身份证号',width:180,align:'center'},
								{field:'mzcard_phone',title:'联系电话',width:125,align:'center'},
						    ]]
						});
				    $("#busfz").textbox("setValue",null); 
				  
				  } 
			}); */
			
			$('#medid').searchbox({
				searcher:function(value,name){
					$('#guahao_tb').datagrid({
					    url:'medidgh?mecard_number='+value,
						pagination:true,
					    pageNumber:1,
					    pageSize:6,
					    pageList:[6,6],
					    columns:[[
							{field:'outpatient_id',title:'门诊号',width:100,align:'center'},
							{field:'mecard_number',title:'诊疗卡号',width:121.5,align:'center'},
							{field:'patient_name',title:'病人姓名',width:101.5,align:'center'},
							{field:'ghlx_name',title:'挂号类型',width:80,align:'center'},
							{field:'registration_date',title:'挂号日期',width:151.5,align:'center',formatter:comformatDate},
							{field:'departments_name',title:'所挂科室',width:80,align:'center'},
							{field:'registration_money',title:'挂号金额',width:80,align:'center'},
							{field:'kzfy',title:'看诊金额',width:100,align:'center'},
							{field:'ghblr',title:'办理人',width:101.5,align:'center'}
					    ]]
					});
					$("#medid").textbox("setValue",null);
				}
			});
			//挂号记录查询---根据医疗卡号
			/* $("#bed_ejection1").click(function(){
				var medid=$('#medid').val();
				if(medid==''){
					$.messager.alert("温馨提示：","输入不能为空");
				}else if(!(/^([1-9]\d*|[0]{1,1})$/).test(medid)){
					$.messager.alert("温馨提示：","请输入数字");
				}else if(medid.length>14){
					$.messager.alert("温馨提示：","长度超出");
				}else if(medid.length<14){
					$.messager.alert("温馨提示：","长度不够");
				}else{
					$('#guahao_tb').datagrid({
					    url:'medidgh?mecard_number='+medid,
						pagination:true,
					    pageNumber:1,
					    pageSize:3,
					    pageList:[3,6],
					    columns:[[
							{field:'outpatient_id',title:'门诊号',width:100,align:'center'},
							{field:'mecard_number',title:'诊疗卡号',width:121.5,align:'center'},
							{field:'patient_name',title:'病人姓名',width:101.5,align:'center'},
							/* {field:'card_cid',title:'病人身份证号',width:180,align:'center'}, 
						
							{field:'ghlx_name',title:'挂号类型',width:80,align:'center'},
							{field:'registration_date',title:'挂号日期',width:151.5,align:'center',formatter:comformatDate},
							{field:'departments_name',title:'所挂科室',width:80,align:'center'},
							{field:'registration_money',title:'挂号金额',width:80,align:'center'},
							{field:'kzfy',title:'看诊金额',width:100,align:'center'},
							{field:'ghblr',title:'办理人',width:101.5,align:'center'}
					    ]]
					});
					$("#medid").textbox("setValue",null); 
				}
			}); */
		});
		
	</script>
		<input type="hidden" type="text" id="mecardnumber"><!-- 医疗卡卡号储存 打印挂号收费票据时调用-->
		<div class="easyui-layout" data-options="region:'west',title:'挂号',split:true,collapsible:false"style="width:600;border:1px  solid  #19AA8D">
				<!-- =============上面信息输入盒子===========  -->
		<fieldset class="guhao_" style="border:1px solid #19AA8D;border-radius:5px;background:white">
			<legend>挂号信息</legend>
			<span>
				<input name="Yi_Id2" id="ghylkh" class="easyui-searchbox"
				data-options="label:'医疗卡号：',prompt:'请输入医疗卡号',width:350,labelAlign:'right'">
				
				<!-- <a id="hgylkh" href="#" class="easyui-linkbutton"
					data-options="iconCls:'icon-search',plain:true" style="width:38px"></a> -->
			</span>
			
			<form action="" id="cw_added" method="post">
			
					<p>
						<span>
							<input name="Name_" id="brxm" class="easyui-textbox"  required="required"
									data-options="label:'病人姓名：',width:260,labelAlign:'right'">
						</span>
						
						<span>
							<input name="Age_" id="brnl" class="easyui-textbox"  required="required"
							data-options="label:'病人年龄：',width:260,labelAlign:'right'">
						</span>
				
						<span>
							<input name="Sex_" id="brxb" class="easyui-textbox"  required="required"
							data-options="label:'病人性别：',width:260,labelAlign:'right'"> 
							
						</span>
						
						 <span>
						 	<input name="Sf_" id="crd" class="easyui-textbox"  required="required"
									data-options="label:'身份证号：',width:260,labelAlign:'right'">
							
						</span>
					</p>
								
					<p>
						<span>
							<input name="Dain_" id="tel" class="easyui-textbox"  required="required"
									data-options="label:'联系电话：',width:260,labelAlign:'right'">
						</span>
						
						<span>
							<select id="department_" class="easyui-combobox" panelHeight='auto'
							data-options="label:'选择科室：',width:260,labelAlign:'right'">   
   									
							</select> 
						</span>
						
						<span>
							<select id="yishen" class="easyui-combobox" panelHeight='auto'
							data-options="label:'选择医生：',width:260,labelAlign:'right'">   
   									  
							</select> 
						</span>
						
						<span>
							<input name="kzfyaa" id="kzfy" class="easyui-textbox" value='10' required="required"
								data-options="label:'看诊费用：',width:260,labelAlign:'right',disabled:true">  
						</span>
						
					</p>
					<p>
						<span>
							 	<select id="department_type" class="easyui-combobox" panelHeight='auto'
							data-options="label:'挂号类型：',width:260,align:'center'">
										  
   									 
							</select> 
						</span>
						
						 <span>
						 	<input name="ghje_" id="ghje" class="easyui-textbox"  required="required"
									data-options="label:'挂号金额：',width:260,labelAlign:'right'"> 
									
						</span>
						
						<span>
							<input name="Diz_" id="brdizhi" class="easyui-textbox"  required="required"
									data-options="label:'现居地址：',width:470,labelAlign:'right'"> 
						</span>
					</p>
					
				
				<!-- =============两个按钮===========  -->
				<div style="border:none;float:left;margin-left:10px;">
					<div style="border:1px solid none;float:left;width:100px;">总计:<span style="color:red;width:100px;" id="ghzje">0</span>元</div>	
					<div style="border:1px solid none;float:left;width:130px;">实收:<input type="text" id="ghss"value="0"style="color:red;width:50px;height:18px;font-size:15px;border:none;"/>元</div>
					<div style="border:1px solid none;float:left;width:80px;">找零:<span id="ghzl"style="color:red;width:100px;">0</span>元</div>
					<div style="float:right;">
						<a class='easyui-linkbutton bao' id="qd"style="margin-left:630px;">确认</a>		
						<a class='easyui-linkbutton qu' id="qx" style="margin-left:5px;">取消</a>
					</div>
				</div>
			</form>
		</fieldset>
		<!-- =============底部盒子===========  -->
		<div class="easyui-layout" style="width:1120;border:none;margin:5px;background:white">
			<div class="di_2" style="margin-bottom:5px;">
				<span>
					<input name="K_id" id="medid" class="easyui-searchbox" 
					data-options="label:'诊疗卡号：',prompt:'请输入医疗卡号或门诊号',width:280,labelAlign:'right'">
					
				</span>
			
			</div>
			<!-- 底部表格 -->
			<table id="guahao_tb" style="height:230px;width:1135px;" singleSelect="true"  class="easyui-datagrid" data-options="fitColumns:true,pagination:true">
		 				
					
			</table>
		</div>
		
		</div>
		
		<!-- 挂号完成弹框 -->
		<div id="ghwc" class="easyui-window" title="挂号完成" style="width:300px;height:190px;"
				data-options="iconCls:'',modal:true,closed:true">
					<div style="margin:35px;margin-left:100px;font-size:16px;">挂号完成！！！</div>
				<p><a class='easyui-linkbutton' id="ghdy"style="margin-left:105px;">打印票据</a>
				
				</p>
		</div>
	<!-- 药品收费票据 -->
	<div id="guahaoshoufei" class="easyui-window" data-options="modal:true,closed:true" title="药品收费单据" style="width:600px;height:400px;padding:10px;">
			<h3 style="margin-left:200px;">平安医院挂号收费票据</h3>
					<div>
					<span style="float:right;">收费时间:<span id="ghsfsj"></span></span>
					<span style="float:left;">编号:<span style="color:red;" id="ghsfbh"></span></span>	
					</div>
					
					<div style="margin-top:50px;margin-bottom:30px;width:500px;border-bottom: 1px solid #ccc;padding: 5px 20px;padding-bottom: 15px;">
							<p>
								<span style="display: inline-block;">
									所挂科室：<input id="patient_hid" class="text-css" disabled="disabled" style="width: 120px;padding: 0 15px;">
								</span>
								<span style="display: inline-block;margin-left: 50px;">
									所挂医生：<input id="bedText" class="text-css" disabled="disabled" style="width: 60px;padding: 0 15px;">
								</span>
							</p>
							<p>
								<span style="display: inline-block;">
									挂号类型：<input id="ghlx_name" class="text-css" disabled="disabled" style="width: 70px;padding: 0 15px;">
										
								</span>
								<span style="display: inline-block;margin-left: 30px;">
									看诊费：<input id="ghpjkzf" class="text-css" style="width: 30px;padding: 0 15px;" disabled="disabled">
								</span>
								<span style="display: inline-block;margin-left: 30px;">
									挂号费：<input id="ghpjghf" class="text-css" disabled="disabled" style="width: 30px;padding: 0 15px;">
								</span>
							</p>
								<span style="display: inline-block;" class="text-css">总费用：<i id="ghzfy"></i></span>
						</div>
					
					
					<div>			
					<span  style="margin-left:20px;width:100px;">实收：<span  style="color:red;" id="ghpjss"></span>元</span>
					<span  style="margin-left:20px;width:100px;">找零：<span  style="color:red;" id="ghpjzl"></span>元 </span>
				 	<span style="margin-left:20px;width:100px;">病人姓名：<span id="ghbrxm"></span></span>
					<span  style="margin-left:20px;width:100px;">收款人：<span id="ghskr"></span></span> 
					</div>	
				<p>
				<span style="float:right;margin-top:-6px;margin-right:30px;"><a class='easyui-linkbutton' id="ghdywc">打印完成</a></span>
				</p>
	</div>
</body>
</html>